<?php
//рус
include_once (_CORE_PATH . "lib_prototype.php");
include_once (_CORE_PATH . "libs/HTMLPurifierLib/HTMLPurifier.auto.php");   
class purifier_class implements lib_prototype_class
{
	private $_config = array();
	
	/**
		настройки для текста статей и разделов
	*/
	private function getConfig($type)
	{
		if (isset($this->_config[$type])) return $this->_config[$type];
		
		$config = HTMLPurifier_Config::createDefault();
		
		switch ($type)
		{		
			case 'comment':			
					$config->set('HTML', 'Allowed', 'a[href|title],em,p,blockquote,ul,ol,li,img[src|height|width|title|alt],sup,s,strike,b,strong,u');
					$config->set('HTML', 'MaxImgLength', '500');
					$config->set('AutoFormat', 'AutoParagraph', true);	
					$config->set('AutoFormat', 'Linkify', true);
					$config->set('AutoFormat', 'RemoveEmpty', true);
					//$config->set('Filter', 'YouTube', true);
				break;
				
			case 'html':
					//$config->set('HTML', 'Allowed', 'a[href|title],em,p,blockquote,ul,ol,li,img');
					//$config->set('HTML', 'MaxImgLength', '600');
				break;

			default: throw new Exception('Неправильный тип конфига');	
		}
		
		return $this->_config[$type] = $config;
	}	
	
	public function purifyHTML($html)
	{
		return HTMLPurifier::getInstance()->purify($html, $this->getConfig('html'));
	}

	public function purifyComment($html)
	{
		return HTMLPurifier::getInstance()->purify($html, $this->getConfig('comment'));
	}	
}    
    
